package com.pipayshop.controller;

import com.pipayshop.entity.Complaint;
import com.pipayshop.entity.dto.ComplaintDTO;
import com.pipayshop.entity.vo.ResponseVO;
import com.pipayshop.exception.BusinessException;
import com.pipayshop.service.ComplaintService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(value = "举报接口", tags = "举报接口")
@RequestMapping("/pipayshopapi/complaint")
public class ComplaintController {
    @Autowired
    ComplaintService complaintService;

    @PostMapping("addComplaint")
    @ApiOperation("添加举报信息")
    public ResponseVO<String> addComplaint(@RequestBody ComplaintDTO complaintDTO) {
        if (complaintDTO == null) {
            throw new BusinessException("invalid_parameter");
        }
        try {
            Complaint complaint = new Complaint();
            BeanUtils.copyProperties(complaintDTO, complaint);
            complaintService.save(complaint);
            return ResponseVO.getSuccessResponseMsg(null, "添加举报信息成功");
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException("add_report_information_failed");
        }
    }

//    @PostMapping("getComplaint")
//    @ApiOperation("查询举报信息")
//    public ResponseVO getComplaint() {
//        return ResponseVO.getSuccessResponseMsg(null, "查询举报信息成功");
//    }
}
